<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>魏远商城</title>
		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<link rel="shortcut icon" href="/favicon.ico">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="css/sm.css">
		<link rel="stylesheet" href="css/sm-extend.css">
		<link rel="stylesheet" href="css/ionicons.css">
		<link rel="stylesheet" href="css/my-order.css">
		<style type="text/css">
			.mui-badge1 {
				line-height: .8rem!important;
				line-height: 1rem;
				padding: 0px 4px;
				color: white;
				border-radius: 100px;
				background-color: #f6383a;
				position: absolute;
				z-index: 20;
				bottom: 17px;
				right: 3px;
			}
			
			.col-20 {
				position: relative;
				top: 0;
				left: 0;
			}
		</style>
	</head>

	<body>
		<div class="page-group">
			<div class="page page-current">
				<!--标题栏-->
				<header class="bar bar-nav">
					<a href="tab-me.html" class="order-back"><img src="img/back-le.png" height="50%"/></a>
					<a class="button button-link iconfont icon-shuaxin1 pull-right"></a>
					<h1 class="title">我的订单</h1>
				</header>
				<!--二级标题栏-->
				<div class="bar bar-header-secondary row no-gutter order-title-box">
					<span style="width: 20%;height: 98%;" class="col-20 active order-title">全部</span>
					<span style="width: 20%;height: 98%;" class="col-20 order-title">待付款<span id="b0" class=" mui-badge1 "></span></span>
					<span style="width: 20%;height: 98%;" class="col-20 order-title">待发货<span id="b1" class=" mui-badge1 "></span></span>
					<span style="width: 20%;height: 98%;" class="col-20 order-title">待收货<span id="b2" class=" mui-badge1"></span></span>
					<span style="width: 20%;height: 98%;" class="col-20 order-title">待评价<span id="b3" class=" mui-badge1"></span></span>
				</div>
				<!--这里是页面内容区域-->
				<div class="content infinite-scroll infinite-scroll-bottom tab-1 " data-distance="10" style="bottom: 0;">
					<ul class="abc">
						<div class="a0"></div>
						<div class="a1"></div>
						<div class="a2"></div>
						<div class="a3"></div>
						<div class="a4"></div>
					</ul>
					<div style="height: 5px;"></div>
					<!--<div class="loading-state">正在加载中 . 请稍后</div>-->
				</div>
			</div>
		</div>

		<script type="text/javascript" src="js/jquery-3.1.1.min.js" charset="UTF-8"></script>
		<script type="text/javascript" src="js/sm.min.js" charset="UTF-8"></script>
		<script type="text/javascript" src="js/sm-extend.min.js" charset="UTF-8"></script>
		<script type="text/javascript" src="js/common.js" charset="UTF-8"></script>
		<script src="js/url.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			document.addEventListener('sxzf', function() {
				$('.a1').html('');
				$('.a2').html('');
				$('.a3').html('');
				$('.a4').html('');
				$('.a0').html('');
				orderList();
			})
			$('.abc').on('tap', '.order', function(event) {
				event.stopPropagation();
				//          	alert($(this).attr('oid'));
				localStorage.deorderid = $(this).attr('oid');
				mui.openWindow({
					url: 'my-order_de.html',
					id: 'order_de',
					show: 'pop-in'
				});
			})

			$('.order-title-box>span').on('tap', function() {
				console.log($(this).index() + '点击')
				$('.bar-header-secondary span').removeClass('active');
				$(this).addClass('active');
				if(($(this).index()) == 0) {
					$('.abc>div').css('display', 'inline-block');
				}
				if(($(this).index()) > 0) {
					$('.abc>div').eq(($(this).index())).css('display', 'inline-block');
					$('.abc>div').eq(($(this).index())).siblings().css('display', 'none');
				}

				if($(this).index() == 1) {
					localStorage.status = 1;
				} else if($(this).index() == 2) {
					localStorage.status = 2;
				} else if($(this).index() == 3) {
					localStorage.status = 3;
				} else if($(this).index() == 4) {
					localStorage.status = 5;
				} else if($(this).index() == 0) {
					localStorage.status = '';
				}

				console.log(localStorage.status + '<<<<<<<localStorage.status');
				$('.a1').html('');
				$('.a2').html('');
				$('.a3').html('');
				$('.a4').html('');
				$('.a0').html('');
				orderList();
			})
			var status_tab = localStorage.status_tab;
			if(status_tab != 0) {
				$('.bar-header-secondary span').removeClass('active');
				$('.order-title-box>span').eq(status_tab).addClass('active');
				$('.abc>div').eq(status_tab).css('display', 'inline-block');
				$('.abc>div').eq(status_tab).siblings().css('display', 'none');
			} else {
				$('.bar-header-secondary span').removeClass('active');
				$('.order-title-box>span').eq(status_tab).addClass('active');
				if(status_tab == 0) {
					$('.abc>div').css('display', 'inline-block');
				}
			}

			window.addEventListener('uporder', function(event) {
				$('.a1').html('');
				$('.a2').html('');
				$('.a3').html('');
				$('.a4').html('');
				$('.a0').html('');
				orderList();
			});
			clist();

			function clist() {
				if(localStorage.status_tab == 1) {
					localStorage.status = 1;
					orderList();
				} else if(localStorage.status_tab == 2) {
					localStorage.status = 2;
					orderList();
				} else if(localStorage.status_tab == 3) {
					localStorage.status = 3;
					orderList();
				} else if(localStorage.status_tab == 4) {
					localStorage.status = 5;
					orderList();
				} else if(localStorage.status_tab == 0) {
					localStorage.status = '';
					orderList();
				}
				console.log(localStorage.status);
			}
			/*点击刷新*/
			$('.pull-right').on('tap', function() {
				updataall();
			})

			function updataall() {
				$('.a1').html('');
				$('.a2').html('');
				$('.a3').html('');
				$('.a4').html('');
				$('.a0').html('');
				orderList();

			}

			//接口
			function orderList() {
				$.ajax({
					url: ur + '/mobilemember/frontOrder/orderlist',
					type: 'post',
					dataType: 'json',
					headers: {
						'X-Token': localStorage.token,
					},
					data: {
						'orderVO.status': localStorage.status
						//								'status':status
					},
					success: function(data) {
						if(data.result.meta.code == 201) {
							var a = JSON.stringify(data.statusNum);
							var b = (a.replace('[', '').replace(']', '')).split(',');
							console.log(b.length);
							console.log(b[0]);
							if(b[0] != 0) {
								$('#b0').text(b[0])
							} else if(b[0] == 0) {
								$('#b0').css('display', 'none');
							}
							if(b[1] != 0) {
								$('#b1').text(b[1])
							} else if(b[1] == 0) {
								$('#b1').css('display', 'none');
							}
							if(b[2] != 0) {
								$('#b2').text(b[2])
							} else if(b[2] == 0) {
								$('#b2').css('display', 'none');
							}
							if(b[3] != 0) {
								$('#b3').text(b[3])
							} else if(b[3] == 0) {
								$('#b3').css('display', 'none');
							}
							var divimg = ('<div style="margin:5rem auto 0;text-align: center;"><img style="width:35%;" src="img/nogood.png"><p style="color:#6a6a6a;font-size: .8rem;">您还没有此类型的订单</p></div>');
							if(localStorage.status == 1) {
								$('.a1').html('');
								$('.a1').append(divimg);
							} else if(localStorage.status == 2) {
								$('.a2').html('');
								$('.a2').append(divimg);
							} else if(localStorage.status == 3) {
								$('.a3').html('');
								$('.a3').append(divimg);
							} else if(localStorage.status == 5) {
								$('.a4').html('');
								$('.a4').append(divimg);
							} else if(localStorage.status == '') {
								$('.a0').html('');
								$('.a0').append(divimg);
							}
							//							                          plus.nativeUI.closeWaiting();
						} else if(data.result.meta.code == 200) {
							var a = JSON.stringify(data.statusNum);
							var b = (a.replace('[', '').replace(']', '')).split(',');
							console.log(b.length);
							console.log(b[0]);
							if(b[0] != 0) {
								$('#b0').text(b[0])
							}
							if(b[1] != 0) {
								$('#b1').text(b[1])
							}
							if(b[2] != 0) {
								$('#b2').text(b[2])
							}
							if(b[3] != 0) {
								$('#b3').text(b[3])
							}
							var n = data.result.data.length;
							var m = data.result.data[0].length;
							console.log(data.result.data.length + 'n')
							console.log(data.result.data[0].length + 'm')
							for(var i = 0; i < n; i++) {
								var howjian = 0;
								var allpric = 0;
								var divall = $('<li class="order" id="daifukuan" oid="' + data.result.data[i][0].orderId + '" Nid="' + data.result.data[i][0].orderNum + '">' +
									'<div class="main" id="order1">' +
									'<div class="order-header clearfix">' +
									'<div class="pull-left order-info">' +
									'<p>' + '店铺名称：' + data.result.data[i][0].shopName + '</p>' +
									'<p class="order-code">' + '订单编号：' + data.result.data[i][0].orderNum + '</p>' +
									'</div>' +
									'<div class="pull-right">' +
									'<a class="fukuan' + i + '' + 0 + ' fukuan"></a>' +
									'</div>' +
									'</div>' +
									'<div class="order-all' + i + '">' +

									'</div>' +
									'<div class="order-footer clearfix">' +
									'<span class="pull-right">共<span class="howjian' + i + ' howjian"></span>件商品&nbsp;&nbsp;&nbsp;&nbsp;合计：¥' + '<i class="order-total allpric' + i + '"></i>&nbsp;&nbsp;' +
									//									'(含运费￥' + (data.result.data[i][0].freight==undefined?data.result.data[i][0].freight:0) + ')</span>' +
									'</div>' +
									'<div class="order-vfooter clearfix">' +
									'<span class="pull-left order-time">' + data.result.data[i][0].createTime.substring(0, 10) + '</span>' +
									'<span class="pull-right"><button class="delete' + i + '' + 0 + ' delete" tai="' + data.result.data[i][0].status + '"></button><button class="payment' + i + '' + 0 + ' payment" tai="' + data.result.data[i][0].status + '"></button></span>' +
									'</div>' +
									'</div>' +
									'</li>'
								);
								if(localStorage.status == 1) {
									//									$('.a1').html('');
									$('.a1').append(divall);
									$('.fukuan' + i + '' + 0 + '').text('等待买家付款');
									$('.delete' + i + '' + 0 + '').text('取消订单');
									$('.payment' + i + '' + 0 + '').text('立即支付');
								} else if(localStorage.status == 2 || localStorage.status == 19) {
									//									$('.a2').html('');
									$('.a2').append(divall);
									$('.fukuan' + i + '' + 0 + '').text('买家已付款');
									$('.delete' + i + '' + 0 + '').text('申请退款');
									$('.payment' + i + '' + 0 + '').text('提醒发货');
								} else if(localStorage.status == 3) {
									//									$('.a3').html('');
									$('.a3').append(divall);
									$('.fukuan' + i + '' + 0 + '').text('卖家已发货');
									$('.delete' + i + '' + 0 + '').text('查看物流');
									$('.payment' + i + '' + 0 + '').text('确认收货');
								} else if(localStorage.status == 5) {
									//									$('.a4').html('');
									$('.a4').append(divall);
									$('.fukuan' + i + '' + 0 + '').text('交易成功');
									$('.delete' + i + '' + 0 + '').text('删除订单');
									$('.payment' + i + '' + 0 + '').css('display', 'none');
								} else if(localStorage.status == '') {
									//									$('.a0').html('');
									$('.a0').append(divall);
									if(data.result.data[i][0].status == 1) {
										//									$('.a1').html('');
										$('.a0').append(divall);
										$('.fukuan' + i + '' + 0 + '').text('等待买家付款');
										$('.delete' + i + '' + 0 + '').text('取消订单');
										$('.payment' + i + '' + 0 + '').text('立即支付');
									} else if(data.result.data[i][0].status == 2 || data.result.data[i][0].status == 19) {
										//									$('.a2').html('');
										$('.a0').append(divall);
										$('.fukuan' + i + '' + 0 + '').text('买家已付款');
										$('.delete' + i + '' + 0 + '').text('申请退款');
										$('.payment' + i + '' + 0 + '').text('提醒发货');
									} else if(data.result.data[i][0].status == 3) {
										//									$('.a3').html('');
										$('.a0').append(divall);
										$('.fukuan' + i + '' + 0 + '').text('卖家已发货');
										$('.delete' + i + '' + 0 + '').text('查看物流');
										$('.payment' + i + '' + 0 + '').text('确认收货');
									} else if(data.result.data[i][0].status == 5) {
										//									$('.a4').html('');
										$('.a0').append(divall);
										$('.fukuan' + i + '' + 0 + '').text('交易成功');
										$('.delete' + i + '' + 0 + '').text('删除订单');
										$('.payment' + i + '' + 0 + '').css('display', 'none');
									} else if(data.result.data[i][0].status == 11) {
										//									$('.a2').html('');
										$('.a0').append(divall);
										$('.fukuan' + i + '' + 0 + '').text('交易关闭');
										$('.delete' + i + '' + 0 + '').text('删除订单');
										$('.payment' + i + '' + 0 + '').css('display', 'none');
									} else if(data.result.data[i][0].status == 9) {
										//									$('.a2').html('');
										$('.a0').append(divall);
										$('.fukuan' + i + '' + 0 + '').text('交易关闭');
										$('.delete' + i + '' + 0 + '').text('删除订单');
										$('.payment' + i + '' + 0 + '').css('display', 'none');
									} else if(data.result.data[i][0].status == 12) {
										//									$('.a2').html('');
										$('.a0').append(divall);
										$('.fukuan' + i + '' + 0 + '').parents('#daifukuan').css('display', 'none');
										//										$('.delete' + i + '' + 0 + '').text('删除订单');
										//										$('.payment' + i + '' + 0 + '').css('display', 'none');
									} else if(data.result.data[i][0].status == 13) {
										//									$('.a2').html('');
										$('.a0').append(divall);
										//										$('.fukuan' + i + '' + 0 + '').parents('#daifukuan').css('display', 'none');
										$('.fukuan' + i + '' + 0 + '').text('退款中');
										$('.delete' + i + '' + 0 + '').css('display', 'none');
										$('.payment' + i + '' + 0 + '').css('display', 'none');
									}
								}
								for(var j = 0; j < data.result.data[i].length; j++) {
									var b = data.result.data[i][j].photoPath;
									var m = b.indexOf(',');
									if(m != '-1') {
										var mainImg = b.substring(0, m);
									} else {
										mainImg = b;
									}
									var div = $(
										'<div class="order-body">' +
										'<div class="product">' +
										'<div class="p-img" style="background-image:url(' + picur + mainImg + ');background-position:center;background-repeat:no-repeat;background-size:cover;"></div>' +
										'<div class="details"><p>' + data.result.data[i][j].shorName + '</p><p class="d' + i + '' + j + '">' + data.result.data[i][j].proVal + '</p></div>' +
										'<div class="details_ri">' +
										'<p>￥' + data.result.data[i][j].price + '</p>' +
										'<p><del>￥' + data.result.data[i][j].oriPrice + '</del></p>' +
										'<p>X' + data.result.data[i][j].amount + '</p>' +
										'<p></p>' +
										'</div>' +
										'</div>' +
										'</div>'
									);
									$('.order-all' + i + '').append(div);
									if(data.result.data[i][j].proVal == "undefined" || data.result.data[i][j].proVal == null) {
										$('.d' + i + '' + j + '').css('display', 'none');
									}
									howjian = howjian + data.result.data[i][j].amount
									allpric = allpric + data.result.data[i][j].price * data.result.data[i][j].amount
									$('.howjian' + i + '').text(howjian);
									$('.allpric' + i + '').text(allpric);
								}
							}
						}
					},
					error: function(e) {
						console.log(JSON.stringify(e) + '<<<<错误');
					}
				})
			}

			/*第一个按钮点击*/
			$('.abc').on('tap', '.delete', function(event) {
				event.stopPropagation();
				//				 event.stopPropagation();
				var tai = $(this).attr('tai');
				if(tai == 1) {
					/*取消订单*/
					var thisid = $(this).parents('.order').attr('oid');
					console.log($(this));
					//                    alert(thisid);
					var all = $(this).parents('.order');
					var btnArray = ['否', '是'];
					mui.confirm('确认取消订单，确认？', '魏远商城', btnArray, function(e) {
						if(e.index == 1) {
							$.ajax({
								url: ur + '/mobilemember/frontOrderOperation/cancel',
								type: 'post',
								headers: {
									"X-Token": localStorage.token
								},
								dataType: 'json',
								data: {
									"orderVO.id": thisid,
								},
								success: function(data) {
									mui.toast('取消订单成功');
									//刷新
									updataall();
								},
								error: function(data) {
									console.log(data);
								}
							})
						}
					})
				} else if(tai == 2) {
					/*退款*/
					var thisid2 = $(this).parents('.order').attr('oid');
					localStorage.backmonm = thisid2;
					console.log($(this));
					mui.openWindow({
						url: 'refoundmon.html',
						id: 'refoundmon',
						show: 'pop-in'
					});
				} else if(tai == 3) {
					/*确认收货*/
					localStorage.lookorderid = $(this).parents('.order').attr('oid');
					mui.openWindow({
						url: 'my-logistics.html',
						id: 'my-logistics',
						show: 'pop-in'
					});

				} else if(tai == 5) {
					/*删除订单*/
					var thisid5 = $(this).parents('.order').attr('oid');
					//                    console.log($(this));
					//                    alert(thisid);
					var all5 = $(this).parents('.order');
					var btnArray = ['否', '是'];
					mui.confirm('确认删除订单，确认？', '魏远商城', btnArray, function(e) {
						if(e.index == 1) {
							//						alert(thisid5);
							$.ajax({
								url: ur + '/mobilemember/frontOrderOperation/orderByDel',
								type: 'post',
								headers: {
									"X-Token": localStorage.token
								},
								dataType: 'json',
								data: {
									"orderVO.id": thisid5,
									/*"id": '40288051594f367a015963128b240033',*/
								},
								success: function(data) {
									console.log(data);
									all5.fadeOut(1000);
									mui.toast('删除订单成功');
									//									plus.webview.getWebviewById('my-order').reload();
								},
								error: function(data) {
									console.log(data);
								}
							})
						}
					})
				} else if(tai == 11) {
					/*删除订单*/
					var thisid11 = $(this).parents('.order').attr('oid');
					console.log($(this));
					//                    alert(thisid);
					var all11 = $(this).parents('.order');
					var btnArray = ['否', '是'];
					mui.confirm('确认删除订单，确认？', '魏远商城', btnArray, function(e) {
						if(e.index == 1) {
							//				alert(thisid);
							$.ajax({
								url: ur + '/mobilemember/frontOrderOperation/orderByDel',
								type: 'post',
								headers: {
									"X-Token": localStorage.token
								},
								dataType: 'json',
								data: {
									"orderVO.id": thisid11,
									/*"id": '40288051594f367a015963128b240033',*/
								},
								success: function(data) {
									console.log(data);
									all11.fadeOut(1000);
									mui.toast('删除订单成功');
								},
								error: function(data) {
									console.log(data);
								}
							})
						}
					})
				}
			});

			/*第二个按钮点击*/
			$('.abc').on('tap', '.payment', function(event) {
				event.stopPropagation();
				var tai = $(this).attr('tai');
				if(tai == 1) {
					/*去到付款*/
					localStorage.alltimes = $(this).parents('.order').find('.howjian').text();
					localStorage.allpriceall = $(this).parents('.order').find('.order-total').text();
					localStorage.sureorder = $(this).parents('.order').attr('Nid');
					localStorage.sureorderid = $(this).parents('.order').attr('oid');
					//				 	alert(localStorage.alltimes );
					//					alert(localStorage.sureorder);
					mui.openWindow({
						url: 'sure.html',
						id: 'sure',
						show: 'pop-in'
					});

				} else if(tai == 2 || tai == 19) {

					/*发货提醒*/
					var thisid2 = $(this).parents('.order').attr('oid');
					console.log($(this));
					//                    alert(thisid);
					var all2 = $(this).parents('.order');
					var btnArray = ['否', '是'];
					mui.confirm('确认提醒发货，确认？', '魏远商城', btnArray, function(e) {
						if(e.index == 1) {
							//				alert(thisid);
							$.ajax({
								url: ur + '/mobilemember/frontOrderOperation/remind',
								type: 'post',
								headers: {
									"X-Token": localStorage.token
								},
								dataType: 'json',
								data: {
									"orderByRemindId": thisid2,
									/*"id": '40288051594f367a015963128b240033',*/
								},
								success: function(data) {
									console.log(data);
									//							all.fadeOut(1000);
									mui.toast('已为您发送提醒信息');
								},
								error: function(data) {
									console.log(data);
								}
							})

						}
					})
				} else if(tai == 3) {
					/*确认收货*/
					var thisid3 = $(this).parents('.order').attr('oid');
					console.log($(this));
					//                    alert(thisid);
					var all3 = $(this).parents('.order');
					var btnArray = ['否', '是'];
					mui.confirm('确认收货，确认？', '魏远商城', btnArray, function(e) {
						if(e.index == 1) {
							//				alert(thisid);
							$.ajax({
								url: ur + '/mobilemember/frontOrderOperation/confirmReceipt',
								type: 'post',
								headers: {
									"X-Token": localStorage.token
								},
								dataType: 'json',
								data: {
									"orderVO.id": thisid3,
									/*"id": '40288051594f367a015963128b240033',*/
								},
								success: function(data) {
									console.log(data);
									//							all.fadeOut(1000);
									mui.toast('确认收货成功');
									updataall();
								},
								error: function(data) {
									console.log(data);
								}
							})
						}
					})
				} else if(tai == 5) {
					localStorage.sureorderid = $(this).parents('.order').attr('oid');
					mui.openWindow({
						url: 'evaluate.html',
						id: 'evaluate',
						show: 'pop-in'
					});
				}

			})
			/*删除订单*/
			//          function delteorder(){
			//                    var thisid = $(this).parents('.order').attr('oid');
			//                    console.log($(this));
			//                    alert(thisid);
			//				      var all = $(this).parents('.order');
			//				var btnArray = ['否', '是'];
			//				mui.confirm('确认取消订单，确认？', '魏远商城', btnArray, function(e) {
			//				if (e.index == 1) {
			////				alert(thisid);
			//					$.ajax({
			//						url: ur + '/mobilemember/frontOrderOperation/cancel',
			//						type: 'post',
			//						headers: {
			//							"X-Token": localStorage.token
			//						},
			//						dataType: 'json',
			//						data: {
			//							"orderVO.id": thisid,
			//							/*"id": '40288051594f367a015963128b240033',*/
			//						},
			//						success: function(data){
			//							console.log(data);
			////							all.fadeOut(1000);
			//							mui.toast('删除成功');
			//						},
			//						error: function(data){
			//							console.log(data);
			//						}
			//					})
			//						
			//				}
			//			})
			//			}
			//立即支付
			//			document.getElementById("payment").addEventListener('tap', function() {
			//					mui.openWindow({
			//						url: '',
			//						id: ''
			//					})
			//				})
			//取消订单order1
			$("#cancel").on('tap', function() {
				//				alert(1111);
				var btnArray = ['否', '是'];
				mui.confirm('确定取消订单？', '提示', btnArray, function(e) {
					//					alert(22);
					if(e.index == 1) {
						$('#order1').remove();
					} else {

					}
				})
			});
			//提醒发货
			//			document.getElementById("remind").getEventListener('tap',function(){
			//				mui.toast('已提醒卖家发货');
			//			})
			//查看物流
			$('.logistics').on('tap', function() {
				mui.openWindow({
					url: 'my-logistics.html',
					id: 'my-logistics',
					show: 'pop-in'
				})
			})
			//待评价
			$('#evaluate').on('tap', function() {
				mui.openWindow({
					url: 'evaluate.html',
					id: 'evaluate',
					show: 'pop-in'
				})
			})
			//立即付款
			//			$('#payment').on('tap', function() {
			//				mui.openWindow({
			//					url: 'sure.html',
			//					id: 'sure',
			//					show: 'pop-in'
			//				})
			//			})
		</script>
	</body>

</html>